#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
const int MAXN=1010;
int n;
string op,ad;
map<string,int>G;
inline bool check(string s){
	int cnt1=0,cnt2=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='.')cnt1++;
		if(s[i]==':'){
			if(cnt1!=3)return false;
			cnt2++;
		}
	}
	if(cnt1!=3||cnt2!=1)return false;
	int x=0;
	if(s[0]=='0'&&(s[1]>='0'&&s[1]<='9'))return false;
	for(int i=0;i<s.length();i++){
		if(s[i]=='.'||s[i]==':'){
			if(x>255)return false;
			if(s[i+1]=='0'&&(s[i+2]>='0'&&s[i+2]<='9'))return false;
			x=0;
		}
		else x=x*10+s[i]-'0';
	}
	if(x>65535)return false;
	return true;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>op>>ad;
		if(!check(ad)){
			printf("ERR\n");
			continue;
		}
		if(op=="Server"){
			if(G[ad]==0){
				printf("OK\n");
				G[ad]=i;
			}
			else{
				printf("FAIL\n");
			}
		}
		if(op=="Client"){
			if(G[ad]>=1&&G[ad]<=n){
				printf("%d\n",G[ad]);
			}
			else{
				printf("FAIL\n");
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
